﻿using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;

namespace SDPChecker
{
   

    public class CqlResultParser
    {
        private TextReader Reader { get; set; }

        public CqlResultParser(TextReader reader)
        {
            Reader = reader;
        }

        public IEnumerable<AssemblyInfo> InstableAssemblies
        {
            get
            {
                var doc = XDocument.Load(Reader);

                var instabilityQuery = (from query in doc.Descendants("Query")
                                        where query.Attribute("Name").Value == "Olavs Instability of assemblies"
                                        select query).FirstOrDefault();
                return from row in instabilityQuery.Descendants("Row")
                             where row.Value != "N/A"
                             select new AssemblyInfo(row.Attribute("Name").Value, decimal.Parse(row.Value, CultureInfo.InvariantCulture));
            }
        }
    }
}
